package hiatao.puzzle.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;

import haitao.puzzle.R;
import hiatao.puzzle.config.MyApplication;
import hiatao.puzzle.config.URLS;
import hiatao.puzzle.utils.ImageUtils;
import hiatao.puzzle.utils.PixelUtil;
import hiatao.puzzle.utils.StatusBarCompat;

public class PreViewActivity  extends Activity implements OnClickListener{

	private ImageView img;
    private View top_back;
    private View confirm;
    private String  url;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_preview);
		findView();
		init();
		StatusBarCompat.compat(this, getResources().getColor(R.color.primary));
	}

	private void init() {
		LayoutParams lp = (LayoutParams) img.getLayoutParams();
		int s= PixelUtil.getScreenWidth(this)-PixelUtil.dp2px(this, 20);
		lp.height=s;
		lp.width = s;
		img.setLayoutParams(lp);
		url =getIntent().getStringExtra("URL");
		ImageUtils.loadImg(url,img);
		top_back.setOnClickListener(this);
		confirm.setOnClickListener(this);
	}

	private void findView() {
        img = (ImageView) findViewById(R.id.img);
        top_back =  findViewById(R.id.top_back);
        confirm =  findViewById(R.id.confirm);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.top_back:
			finish();
			break;
		case R.id.confirm:
			Intent intent = new Intent();
			intent.setClass(PreViewActivity.this, PuzzleGameActivity.class);
			intent.putExtra("URL",url);
			if(MyApplication.getInstance().user!=null){
				intent.putExtra("HEADURL",MyApplication.getInstance().user.getHeadUrl());
				intent.putExtra("NAME",MyApplication.getInstance().user.getName());
				intent.putExtra("INTRO",MyApplication.getInstance().user.getIntro());
			}else{
				intent.putExtra("HEADURL",URLS.BASE_USER+15+".png");
				intent.putExtra("NAME","轻狂");
				intent.putExtra("INTRO","不达成功誓不休");
			}
			
			startActivity(intent);
			finish();
			break;

		default:
			break;
		}
	}
	
}
